package com.longrise.co.ui.carfiles.widget;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Point;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

import com.longrise.co.R;

/**
 * Created by luoyang on 2017-7-17.
 */

public class EvaluationSuccessDialog extends Dialog {

    private View.OnClickListener mListener;

    public EvaluationSuccessDialog(@NonNull Context context) {
        super(context);
        initView(context);
    }

    public EvaluationSuccessDialog(@NonNull Context context, @StyleRes int themeResId) {
        super(context, themeResId);
        initView(context);
    }

    protected EvaluationSuccessDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        initView(context);
    }

    private void initView(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_evaluation, null);
        setContentView(view);
        Button btn = (Button)view.findViewById(R.id.confirm);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.onClick(v);
            }
        });
        //设置点击事件
        //设置dialog大小，这里是一个小赠送，模块好的控件大小设置
        Window dialogWindow = getWindow();
        WindowManager manager = ((Activity) context).getWindowManager();
        WindowManager.LayoutParams params = dialogWindow.getAttributes(); // 获取对话框当前的参数值
        dialogWindow.setGravity(Gravity.CENTER);//设置对话框位置
        Display d = manager.getDefaultDisplay(); // 获取屏幕宽、高度
        Point outPoint = new Point();
        d.getSize(outPoint);
        params.width = (int) (outPoint.x * 0.8); // 宽度设置为屏幕的0.8，根据实际情况调整
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        dialogWindow.setAttributes(params);
    }

    public void setOnclickListener(View.OnClickListener listener) {
        mListener = listener;
    }


}
